package xiaodou.data
{
	[Bindable]
	public class SelectObject
	{
		/**
		 * 把一个数组转换成 SelectObject对象数组，其中每一项的data属性是原始数组的对应项
		 * @param array 原始数组
		 * @param defaultSelect 默认是否选中
		 * @return SelectObject对象的数组
		 * 
		 */		
		public static function toSelectedObjectArray(array:Array, defaultSelect:Boolean = false):Array
		{
			if(array == null)
				return null;
			else
			{
				var result:Array = new Array();
				for (var i:int = 0; i < array.length; i++) 
				{
					var item:SelectObject = new SelectObject(array[i], defaultSelect);
					result.push(item);
				}
				return result;
			}
		}
		
		/**
		 * 把 SelectObject对象数组 还原为普通数组
		 * @param selectedObjectArr
		 * @return 
		 * 
		 */		
		public static function toObjectArray(selectedObjectArr:Array):Array
		{
			if(selectedObjectArr == null)
				return null;
			else
			{
				var result:Array = new Array();
				for (var i:int = 0; i < selectedObjectArr.length; i++) 
				{
					result.push(selectedObjectArr[i].data);
				}
				return result;
				
			}
		}
		
		public var selected:Boolean;
		public var data:*;
		public function SelectObject(data:*, selected:Boolean = false)
		{
			this.data = data;
			this.selected = selected;
		}
	}
}